define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'device_order/index' + location.search,
                    add_url: 'device_order/add',
                    edit_url: 'device_order/edit',
                    del_url: 'device_order/del',
                    multi_url: 'device_order/multi',
                    import_url: 'device_order/import',
                    table: 'device_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'orderid', title: __('Orderid'), operate: false},
                        {field: 'ground.name', title: __('Ground.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'device.name', title: __('Device.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id')},
                        // {field: 'ground_id', title: __('Ground_id')},
                        // {field: 'device_id', title: __('Device_id')},
                        {field: 'type', title: __('Type'), operate:false,searchList: {"rs":__('Type rs'),"js":__('Type js'),"qs":__('Type qs')}, formatter: Table.api.formatter.normal},
                        {field: 'yd_time', title: __('Yd_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'amount', title: __('Amount'), operate:false},
                        {field: 'payamount', title: __('Payamount'), operate:false},
                        {field: 'paytype', title: __('Paytype'), searchList: {"wechat":__('微信'),"money":__('余额支付'), "free_coupon":__('免单券支付')}, formatter: Table.api.formatter.status},
                        {field: 'paytime', title: __('Paytime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'memo', title: __('Memo'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), operate:false,searchList: {"created":__('Status created'),"paid":__('Status paid'),"expired":__('Status expired')}, formatter: Table.api.formatter.status},
                        // {field: 'device_status', title: __('Device_status'),operate:false, searchList: {"1":__('Device_status 1'),"0":__('Device_status 0')}, formatter: Table.api.formatter.status},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons:[
                                {
                                    name: 'refund',
                                    text:'退款',//按钮名称
                                    title:'退款',//按钮名称
                                    classname: 'btn btn-xs btn-success btn-view btn-dialog',
                                    icon: 'fa fa-list',
                                    url: function (row) {
                                        return 'device_order/refund?id='+row.id
                                    },
                                },


                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        refund: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
